//window.localStorage.isWeiXin
import cTitle from "components/title";
import inputList from "components/input_list";
// import diyorm from "components/new_diyform";
import diyform from "components/ui_components/yz_diyformV2";
import car_number_keyboard_popup from "../car-manage/components/car-number-keyboard-popup.vue"
import {
  Toast
} from "vant";
export default {
  //name: 'login',
  data() {
    return {
      isInternational: window.isInternational || false,//多语言国际版是否开启，true为开启
      form: {
        name: '',
        sex: 0,
        birthday: "",
        detailedAddress: '',
        dataTime: '请选择',
        accountNumber: '', //账号
        password: '', //密码
        text: '', //文本
        invite_code: '',
        address: '',
        login_checked: false, //协议是否勾选按钮
        field: '', //自定义固定字段
        nickname: '', //昵称
        fathername: '', //父亲姓名
        mothername: '', //母亲姓名
        idcard:'',
        idcard_addr:''
      },
      fileList: [],
      pageType: "register",
      message: '',
      districtName: '', //地址
      district: district,
      sexShow: false, //性别选择弹窗
      birthdayShow: false, //生日选择弹窗
      showAdd: false, //地区选择弹窗
      dropDownBoxShow: false, //下拉框弹窗
      dateTimeShow: false, //日期时间弹窗
      inputShowList: {}, //组件输入框是否显示
      fixedDiyField: '', //自定义字段(固定)
      invite: '', //邀请码信息
      diyform: '', //自定义表单
      registerBasicInfo: {},
      nameOfTheMall: '', //商城名称
      userProtocol: '', //用户协议
      diyField: '', //自定义字段
      diyStatus: 0, //是否存在自定义表单
      changeNickname: false, //是否可以更改昵称
      changePicture: false, //是否可以更改头像
      member_id: '',
      form_id: "",
      fileList: [{
        url: "",
        isImage: true
      }], //头像图片
      orderLocationObj: {
        positioning_success: 0,
        register_province: "",
        register_city: ""
      },
      sexLIst: [{ //性别选择列表
        value: "男",
        url: require('@/assets/images/sex_man.png'),
        checkedUrl: require('@/assets/images/checked_sex_man.png'),
        checked: false
      }, {
        value: "女",
        url: require('@/assets/images/sex_girl.png'),
        checkedUrl: require('@/assets/images/checked_sex_girl.png'),
        checked: false
      }],
      dataList: '', //注册页数据
      minDate: new Date(1900, 0, 1),
      maxDate: new Date(2032, 12, 0),
      currentDate: new Date(),
      openPlatformAgreement: false,
      popoverProtocolContent: '',
      platformAgreement:'',//平台协议
      fixedFieldModification:false, //固定字段是否可只读
      email_register:0,
      car_manage_is_register_bind:false
    };
  },
  activated() {
    if (this.pageType == 'register') { //用户注册页面
      this.fun.setWXTitle('用户注册')
      this.registration()
    } else { //用户信息页面
      this.fun.setWXTitle('基本信息')
      this.essentialInformation()
    }
  },
  async mounted() {
    if (JSON.parse(window.localStorage.getItem("globalParameter")).register_locate == true) {
      this.orderLocationObj = await this.getCurrentOrderLocation();
    }
    if (this.$route.query.pageType) {
      this.pageType = this.$route.query.pageType;
    }
  },
  methods: {
    sexSwitch(e) { //性别切换
      this.sexLIst.forEach((item, index) => {
        if (e == index) {
          let arry = this.sexLIst[index].checked = true
          this.$set(this.sexLIst[index], index, arry)
          if (e == 1) {
            this.form.sex = 2
          } else {
            this.form.sex = 1
          }
        } else {
          let arry = this.sexLIst[index].checked = false
          this.$set(this.sexLIst[index], index, arry)
        }
      })
    },
    openOpenPlatformAgreement(e) { //弹出用户协议弹窗
      this.openPlatformAgreement = true;
      this.agreementContent(e)
    },
    agreementContent(e) { //获取协议内容
      e == 'user'?this.popoverProtocolContent = this.userProtocol:(e == 'platform'?this.popoverProtocolContent = this.platformAgreement:'')
    },
    //时间选择组件方法
    formatDate(date, type) {
      if (type == "dataTime") {
        return `${date.getYear()+1900}-${date.getMonth() + 1}-${date.getDate()}`;
      } else {
        return `${date.getMonth() + 1}-${date.getDate()}`;
      }
    },
    beforeRead(){
      if(!this.changePicture) return;
      this.$dialog.confirm({
        title: '提示',
        message: '相机权限使用说明:\n 需要您的同意才能访问相机拍照来上传自定义头像照片',
      })
        .then(() => {
          this.$refs.uploader.chooseFile();
        })
        .catch(() => {
          return false;
        });
    },
    //头像上传
    afterRead(e) {
      let fd = new FormData();
      fd.append("file", e.file);
      let uploadUrl = this.fun.getRealUrl("upload.uploadPic", {});
      Toast.loading({
        duration: 0, // 持续展示 toast
        message: '上传中...',
        forbidClick: true
      });
      axios
        .post(uploadUrl, fd, {
          headers: {
            "Content-Type": "multipart/form-data"
          }
        })
        .then(response => {
          var responseData = response.data;
          Toast.clear();
          Toast(responseData.msg);
          if (responseData.result === 1) {
            this.fileList[0].url = responseData.data.img_url;
            this.form.avatar = responseData.data.img;
          }
        })
        .catch(error => {
          Toast.clear();
          console.log(error);
        });
    },
    onConfirm(date) { //生日时间选择
      this.birthdayShow = false;
      this.form.birthday = this.formatDate(date, "dataTime");
    },
    dataTimeFiem(date) { //日期时间选择
      this.dateTimeShow = false;
      this.form.dataTime = this.formatDate(date, "dataTime");
    },
    // 城市结果
    resultAdd(district) {
      this.form.address = district;
      this.initDistrict("", district);
    },
    initDistrict(data, district) {
      if (!this.fun.isTextEmpty(data)) {
        if (data.area_name) {
          this.districtName = data.province_name + " " + data.city_name + " " + data.area_name;
        }
        return;
      }

      if (!this.fun.isTextEmpty(district)) {
        this.districtName = district.itemName1 + " " + district.itemName2 + " " + district.itemName3;
      }
    },
    updateInfo() { //更新用户资料
      $http.get("member.logout.index").then(
        response => {
          if (response.result == 1) {
            window.localStorage.setItem("isWxLogin", -1);
            this.$store.commit("savemodel", {});
            localStorage.setItem("token", "");
            localStorage.setItem("loginUid", "");
            window.firstLogin = 0;
            clearLoginData(); // 方法在index.html
            location.reload();
            // this.$dialog
            //   .alert({ message: response.msg })
            //   .then(() => {
            //     location.reload();
            //   })
            //   .catch(() => {});
          }
        },
        response => {
          console.log(response.msg);
        }
      );
    },
    //获取当前位置信息，用于提交订单
    getCurrentOrderLocation() {
      return new Promise((resolev, reject) => {
        Toast.loading({
          message: "获取位置信息",
          forbidClick: true
        });
        var mapObj = new AMap.Map("iCenter");
        mapObj.plugin("AMap.Geolocation", () => {
          var geolocation = new AMap.Geolocation({
            enableHighAccuracy: true, // 是否使用高精度定位，默认:true
            timeout: 10000, // 超过10秒后停止定位，默认：无穷大
            maximumAge: 0, // 定位结果缓存0毫秒，默认：0
            convert: true, // 自动偏移坐标，偏移后的坐标为高德坐标，默认：true
            showButton: true, // 显示定位按钮，默认：true
            buttonPosition: "LB", // 定位按钮停靠位置，默认：'LB'，左下角
            buttonOffset: new AMap.Pixel(10, 20), // 定位按钮与设置的停靠位置的偏移量，默认：Pixel(10, 20)
            showMarker: true, // 定位成功后在定位到的位置显示点标记，默认：true
            showCircle: true, // 定位成功后用圆圈表示定位精度范围，默认：true
            panToLocation: true, // 定位成功后将定位到的位置作为地图中心点，默认：true
            zoomToAccuracy: true // 定位成功后调整地图视野范围使定位位置及精度范围视野内可见，默认：false
          });
          mapObj.addControl(geolocation);
          geolocation.getCurrentPosition();
          AMap.event.addListener(geolocation, "complete", obj => {
            Toast.clear();
            //console.log("执行1");
            resolev({
              positioning_success: 1,
              register_province: obj.addressComponent.province,
              register_city: obj.addressComponent.city
            });
          }); // 返回定位信息
          AMap.event.addListener(geolocation, "error", () => {
            Toast.clear();
            //console.log("执行2");
            resolev({
              positioning_success: 0,
              register_province: "",
              register_city: ""
            });
          }); // 返回定位出错信息
        });
      });
    },
    essentialInformation() { //基本信息页数据
      $http.get("member.member-info.user-info", {
        basic_info: 1
      }).then(
        response => {
          if (response.result == 1) {
            this.form.nickname = response.data.nickname
            this.form.avatar = response.data.avatar
            this.fileList[0].url = response.data.avatar_image;
            this.diyform = response.data.diy_form
            this.nameOfTheMall = response.data.name
            // this.userProtocol = response.data.agreement
            this.changeNickname = response.data?.can_update_nickname
            this.diyField = response.data?.diy_field
            this.fixedDiyField = response.data?.fixed_diy_field
            this.changePicture = response.data?.can_update_avatar
            response.data.basic_info.forEach((item, index) => {
              this.registerBasicInfo[item.field] = item
            });
            this.form.idcard = this.registerBasicInfo?.idcard?.value;
            this.form.idcard_addr = this.registerBasicInfo?.idcard_addr?.value;
            this.form.name = this.registerBasicInfo?.name?.value
            this.form.sex = this.registerBasicInfo?.gender?.value
            if(this.registerBasicInfo?.birthday?.value?.birthyear != ""){ //生日赋值
              this.form.birthday = this.registerBasicInfo?.birthday?.value?.birthyear + '-' + this.registerBasicInfo
                ?.birthday?.value?.birthmonth + '-' + this.registerBasicInfo?.birthday?.value?.birthday
              this.currentDate = new Date(this.registerBasicInfo?.birthday?.value?.birthyear,this.registerBasicInfo
                ?.birthday?.value?.birthmonth-1, this.registerBasicInfo?.birthday?.value?.birthday)
            }
            if(this.registerBasicInfo.address?.value?.province_name != ""){ //地址赋值
              this.districtName = this.registerBasicInfo.address?.value?.province_name + '  ' + this.registerBasicInfo
                ?.address?.value?.city_name + '  ' + this.registerBasicInfo?.address?.value?.area_name
            }
            this.form.address = this.registerBasicInfo?.address?.value
            this.form.detailedAddress = this.registerBasicInfo?.address?.value.address
            this.diyStatus = response.data?.diy_form?.status
            if(this.fixedDiyField.length>0 && this.fixedDiyField[0].value != ''){
              this.fixedFieldModification = true
            }
            if (this.registerBasicInfo.gender.value == 1) { //性别赋值
              this.sexLIst[0].checked = true
              this.sexLIst[1].checked = false
            }else if(this.registerBasicInfo.gender.value == 2){
              this.sexLIst[0].checked = false
              this.sexLIst[1].checked = true
            }
            if (this.fixedDiyField.length > 0) {
              this.form.field = response.data.fixed_diy_field[0].value
            }
          } else {
            this.$dialog.alert({
              message: response.msg
            });
          }
        },
        response => {
          console.log(response.msg);
        }
      );
    },
    registration() { //获取注册页数据
      $http.get("member.register.register-page", {
        basic_info: 1
      }).then(
        response => {
          if (response.result == 1) {
            if(response.data.status && response.data.status == 'redirec' && response.data.url){
              // 处理后台开启微信授权登录，但是直接点击注册页面链接进去，可以进行注册
              // 修改为：进入后授权登录，登录后跳转接口返回的手机号
              window.location.href = response.data.url;
              return;
            }
            this.dataList = response.data
            let basic_info = JSON.parse(localStorage.getItem("yz_basic_info"))
            const captcha = response.data.get_captcha?.captcha;
            this.inputShowList['img'] = captcha?.img;
            this.inputShowList['captchaShow'] = captcha?.status == '1' ? true : false;
            this.inputShowList['passwordInputShow'] = response.data.is_password == '1' ? true : false
            this.inputShowList['countryCodeShow'] = response.data.getInviteCode?.json?.country_code == '1' ? true :
              false;
            this.inputShowList['logPlugIn'] = basic_info?.plugin_setting?.account_login?.enable == 1?true:false;
            this.inputShowList['need_family'] = basic_info?.plugin_setting?.account_login?.need_family == 1?true:false;
            this.inputShowList['min_char'] = basic_info?.plugin_setting?.account_login?.next_enable;
            this.fixedDiyField = response.data.fixed_diy_field
            this.invite = response.data.getInviteCode?.json
            this.diyform = response.data.diy_form
            this.nameOfTheMall = response.data.name
            this.userProtocol = response.data.agreement
            this.platformAgreement = response.data.platform_agreement
            this.diyField = response.data.diy_field
            this.diyStatus = response.data?.diy_form?.status
            this.form.login_checked = response.data.agreement?.default_tick
            this.enable_btn = basic_info?.plugin_setting?.account_login?.enable;
            this.email_register = basic_info?.plugin_setting?.email_register?.is_open;
            this.form.login_checked = response.data.agreement?.default_tick == 1?true:false; //默认勾选
            if(basic_info.plugin_setting?.car_manage?.is_register_bind){
              // 车辆管理注册车牌显示开关
              this.car_manage_is_register_bind = basic_info.plugin_setting?.car_manage?.is_register_bind;
            }
            if (this.enable_btn == 1) { //如果后台开了账号登录插件
              this.inputShowList['passwordInputShow'] = true
            }
            if(!this.fun.isTextEmpty(this.invite.invitation_code)){ //判断是否为邀请二维码进入
                this.form.invite_code = this.invite.invitation_code.invite_code
            }else{
              if (this.invite.status == 1) {
                this.form.invite_code = this.invite.default_invite
              }
            }
            response.data.register_basic_info.forEach((item, index) => {
              this.registerBasicInfo[item.field] = item
            });
          } else {
            this.$dialog.alert({
              message: response.msg
            });
          }
        },
        response => {
          console.log(response.msg);
        }
      );
    },
    async register() { //提交注册
      let that = this;
      if(this.$refs.input_list.radio != '1'){
        if (this.fun.isTextEmpty(this.$refs.input_list.form.mobile) && !this.inputShowList.logPlugIn) {
          Toast("请填写手机号");
          return;
        }


        if (this.$refs.input_list.form.country == "86" && this.fun.isMoblie(this.$refs.input_list.form.mobile) && !this.inputShowList.logPlugIn) {
          Toast("请填写正确的手机号");
          return;
        }

        if (this.fun.isTextEmpty(this.$refs.input_list.form.code) && !this.inputShowList.logPlugIn) {
          Toast("请填写验证码");
          return
        }
      }
      if(this.$refs.input_list.radio == '1' && this.email_register){
        // 开启了邮箱并且选中了邮箱注册
        if (this.fun.isTextEmpty(this.$refs.input_list.form.mobile) && !this.inputShowList.logPlugIn) {
          Toast("请填写邮箱");
          return;
        }
        if (this.fun.isEmail(this.$refs.input_list.form.mobile) && !this.inputShowList.logPlugIn) {
          Toast("请填写正确的邮箱");
          return;
        }
        if (this.fun.isTextEmpty(this.$refs.input_list.form.code) && !this.inputShowList.logPlugIn) {
          Toast("请填写验证码");
          return;
        }
      }

      if (this.fun.isTextEmpty(this.$refs.input_list.form.account) && this.inputShowList.logPlugIn) {
        Toast("请填写账号");
        return;
      }

      if (this.$refs.input_list.form.account.length < this.inputShowList.min_char && this.inputShowList.logPlugIn) {
        Toast(`账号必须不低于${this.inputShowList.min_char.length}位数`);
        return;
      }

      if (this.fun.isTextEmpty(this.$refs.input_list.form.password) && this.inputShowList.passwordInputShow) {
        Toast("请填写密码");
        return;
      }
      if (this.$refs.input_list.form.password.length < 6 && this.inputShowList.passwordInputShow) {
        Toast("密码必须不低于六位数");
        return;
      }

      if (this.fun.isTextEmpty(this.form.invite_code) && this.invite.status == 1 && this.invite.required == 1) {
        Toast("请填写邀请码");
        return;
      }

      if (this.inputShowList.logPlugIn && this.fun.isTextEmpty(this.form.fathername) && this.inputShowList.need_family) {
        Toast("请填写父亲姓名");
        return;
      }

      if (this.inputShowList.logPlugIn && this.fun.isTextEmpty(this.form.mothername) && this.inputShowList.need_family) {
        Toast("请填写母亲姓名");
        return;
      }

      if (this.registerBasicInfo.name && this.registerBasicInfo.name.show && this.registerBasicInfo.name.must == 1 &&
        this.fun.isTextEmpty(this.form.name)) {
        Toast("请填写姓名");
        return;
      }
      if (this.registerBasicInfo.gender && this.registerBasicInfo.gender.show && this.registerBasicInfo.gender.must ==
        1 && this.fun.isTextEmpty(this.form.sex)) {
        Toast("请选择性别");
        return;
      }

      if (this.registerBasicInfo.birthday && this.registerBasicInfo.birthday.show && this.registerBasicInfo.birthday
        .must == 1 && this.fun.isTextEmpty(this.form.birthday)) {
        Toast("请选择生日");
        return;
      }

      if (this.registerBasicInfo.address && this.registerBasicInfo.address.show && this.registerBasicInfo.address
        .must == 1 && this.fun.isTextEmpty(this.districtName)) {
        Toast("请填写地址");
        return;
      }

      if (this.registerBasicInfo.idcard && this.registerBasicInfo.idcard.show && this.registerBasicInfo.idcard
        .must == 1 && this.fun.isTextEmpty(this.form.idcard)) {
        Toast("请填写身份证");
        return;
      }

      if (this.registerBasicInfo.idcard_addr && this.registerBasicInfo.idcard_addr.show && this.registerBasicInfo.idcard_addr
        .must == 1 && this.fun.isTextEmpty(this.form.idcard_addr)) {
        Toast("请填写身份证地址");
        return;
      }
      if (this.fixedDiyField.length > 0) {
        let status = true
        let msg = ''
        this.fixedDiyField.forEach((item, index) => {
          if (this.fun.isTextEmpty(this.form.field) && item.must == 1) {
            msg = item.name
            status = false
          }
        })
        if (!status) {
          Toast("请填写" + msg);
          return
        }
      }
      if (!this.fun.isTextEmpty(this.diyField) && this.diyField?.form.length > 0 && this.diyField?.form_open == 1) {
        let status = true
        let msg = ''
        this.diyField.form.forEach((item, index) => {
          if (this.fun.isTextEmpty(item.value)) {
            msg = item.name
            status = false
          }
        })
        if (!status) {
          Toast("请填写" + msg);
          return
        }
      }

      //判断协议是否勾选
      let protocolState = ''
      if(this.userProtocol.status == 1 ||  this.platformAgreement.status == 1){
        protocolState = true
      }
      if(protocolState && !this.form.login_checked){
        Toast("请勾选协议");
        return;
      }

      if (this.diyStatus == 1) {
        let success_diyform = this.$refs.gofunarr.validation();
        if (!this.$refs.gofunarr.isValidation) {
          return;
        }
      }

      let json = {
        mobile: this.$refs.input_list.form.mobile,
        password: this.$refs.input_list.form.password,
        code: this.$refs.input_list.form.code,
        account: this.$refs.input_list.form.account,
        invite_code: this.form.invite_code,
        name: this.form.name,
        birthday: this.form.birthday,
        custom_value: this.form.field,
        positioning_success: this.orderLocationObj.positioning_success,
        idcard: this.form.idcard,
        idcard_addr: this.form.idcard_addr,
        register_type:this.$refs.input_list.radio == '0'?1:2
      }
      // 石油项目->车辆管理->注册验证车辆车牌信息，car_manage_is_register_bind插件开关
      if(this.car_manage_is_register_bind){
        let carInfoValidationResult = await this.$refs.carInfo.validation();
        if(carInfoValidationResult.status){
          json.car_info = {
            license_no:carInfoValidationResult.carNumber,
            license_colour:carInfoValidationResult.licensePlate,
            car_type:carInfoValidationResult.radio
          }
        }else{
          Toast('请完善车牌');
          return
        }
      }
      if(this.registerBasicInfo.gender && this.registerBasicInfo.gender.show){
        json['gender'] = this.form.sex
      }
      //地址处理
      if (this.registerBasicInfo.address.show && this.form.address != '') {
        json['address'] = this.addressToDealWith(this.form)
      }


      //自定义字段加值
      if (!this.fun.isTextEmpty(this.diyField) && this.diyField.form.length > 0) {
        let json1 = {}
        this.diyField.form.forEach((item, index) => {
          json1[item.field] = item.value
        })
        json['customDatas'] = json1
      }

      //会员标签-记录会员用什么设备注册
      let system_type = this.fun.getTyep();
      if (system_type == 1) {
        json['system_type'] = 'wechat';
      } else if (system_type == 7) {
        json['system_type'] = 'app';
      } else if (system_type == 8) {
        json['system_type'] = 'ali';
      } else if (system_type == 5 && this.fun.isPc()) {
        json['system_type'] = 'pc';
      } else if (system_type == 5 && !this.fun.isPc()) {
        json['system_type'] = 'h5';
      }

      let url = '';
      if (this.inputShowList.logPlugIn) {
        json['fathername'] = this.form.fathername
        json['mothername'] = this.form.mothername
        url = 'plugin.account-login.frotend.member.register'
      } else {
        url = 'member.register.register'
      }

      $http.post(url, json, '提交中').then(
        response => {
          if (response.result == 1) {
            let query = {};
            let isAppCoinK = this.$route.query.CoinK || false;//是否来着第三方app的跳转
            if(isAppCoinK) query.CoinK = 1;

            this.member_id = response.data.uid;
            this.$store.commit("savemodel", response.data);
            this.$dialog.alert({
              message: "注册成功",
              callback: () => {}
            });
            if (this.fun.isTextEmpty(this.diyStatus)) {
              that.$router.push(this.fun.getUrl("login",{},query));
            } else if (this.diyStatus == 1) {
              //去提交diy
              this.$refs.gofunarr.submit();
              this.$router.push(this.fun.getUrl("login",{},query));
            }
          } else {
            if(response.data.link){
              this.$dialog
                .confirm({ message: "车牌已经被绑定", confirmButtonText: "去申诉", confirmButtonColor: "#F15353" })
                .then(() => {
                  window.location.href = response.data.link;
                })
                .catch(() => {});
              return
            }
            this.$dialog.alert({
              message: response.msg
            });
          }
        },
        response => {
          console.log(response.msg);
        }
      );
    },
    modifyingUserInformation() { //提交用户信息修改
      if (this.registerBasicInfo.name && this.registerBasicInfo.name.show && this.registerBasicInfo.name.must == 1 &&
        this.fun.isTextEmpty(this.form.name)) {
        Toast("请填写姓名");
        return;
      }
      if (this.registerBasicInfo.gender && this.registerBasicInfo.gender.show && this.registerBasicInfo.gender.must ==
        1 && this.fun.isTextEmpty(this.form.sex)) {
        Toast("请选择性别");
        return;
      }
      if (this.registerBasicInfo.birthday && this.registerBasicInfo.birthday.show && this.registerBasicInfo.birthday
        .must == 1 && this.fun.isTextEmpty(this.form.birthday)) {
        Toast("请选择生日");
        return;
      }
      if (this.registerBasicInfo.address && this.registerBasicInfo.address.show && this.registerBasicInfo.address
        .must == 1 && this.fun.isTextEmpty(this.districtName)) {
        Toast("请填写地址");
        return;
      }

      if (this.fixedDiyField.length > 0) {
        let status = true
        let msg = ''
        this.fixedDiyField.forEach((item, index) => {
          if (this.fun.isTextEmpty(this.form.field) && item.must == 1) {
            msg = item.name
            status = false
          }
        })
        if (!status) {
          Toast("请填写" + msg);
          return
        }
      }
      if (!this.fun.isTextEmpty(this.diyField) && this.diyField?.form.length > 0 && this.diyField?.form_open == 1) {
        let status = true
        let msg = ''
        this.diyField.form.forEach((item, index) => {
          if (this.fun.isTextEmpty(item.value)) {
            msg = item.name
            status = false
          }
        })
        if (!status) {
          Toast("请填写" + msg);
          return
        }
      }

      if (this.diyStatus == 1) {
        let success_diyform = this.$refs.gofunarr.validation();
        if (!this.$refs.gofunarr.isValidation) {
          return;
        }
      }

      let json = {
        avatar: this.form.avatar,
        nickname: this.form.nickname,
        name: this.form.name,
        birthday: this.form.birthday,
        custom_value: this.form.field,
        idcard:this.form.idcard,
        idcard_addr:this.form.idcard_addr
      }

      if(this.registerBasicInfo.gender && this.registerBasicInfo.gender.show){
        json['gender'] = this.form.sex
      }

      //地址处理
      if (!this.fun.isTextEmpty(this.form.address.province) && !this.fun.isTextEmpty(this.form.address
          .city)) { //如果有回显直接传回显的地址
        this.form.address.address = this.form.detailedAddress
        json['address'] = this.form.address
      } else { //重新选择地址
        if (this.registerBasicInfo.address.show && this.form.address != '') {
          json['address'] = this.addressToDealWith(this.form)
        }
      }

      //自定义字段加值
      if (!this.fun.isTextEmpty(this.diyField) && this.diyField.form.length > 0) {
        let json1 = {}
        this.diyField.form.forEach((item, index) => {
          json1[item.field] = item.value
        })
        json['customDatas'] = json1
      }
      let that = this

      $http.post('member.member-info.user-info-save', json, '正在提交数据...').then(
        response => {
          if (response.result == 1) {
            if (that.fun.isTextEmpty(that.diyStatus)) {
              that.$dialog.alert({
                message: response.msg
              });
              that.$router.go(-1);
            } else if (that.diyStatus == 1) {
              //去提交diy
              that.$dialog.alert({
                message: response.msg
              });
              that.$refs.gofunarr.submit();
              that.$router.go(-1);
            }
          } else {
            that.$dialog.alert({
              message: response.msg
            })
          }
        },
        response => {
          that.$dialog.alert({
            message: response.msg
          });
        }
      );
    },
    addressToDealWith(value) { //地址处理
      let addressJson = {};
      addressJson['province'] = value.address.itemValue1
      addressJson['city'] = value.address.itemValue2
      addressJson['area'] = value.address.itemValue3
      addressJson['province_name'] = value.address.itemName1
      addressJson['city_name'] = value.address.itemName2
      addressJson['area_name'] = value.address.itemName3
      addressJson['address'] = value.detailedAddress
      return addressJson
    },

    postDiy(e, member_id = this.member_id) {
      var that = this;
      var formData = e;

      let json = {
        form_data: formData,
        form_id: this.diyform.id,
        member_id: member_id,
        form_type: "register"
      };
      $http.post("plugin.diyform.api.diy-form.save-diy-form-data", json, "提交中...").then(
        response => {
          if (response.result == 1) {} else {
            this.$dialog.alert({
              message: response.msg
            });
          }
        },
        response => {
          this.$dialog.alert({
            message: response.msg
          });
        }
      );
    }
  },
  components: {
    cTitle,
    inputList,
    diyform,
    car_number_keyboard_popup
    // diyorm
  }
};
